package jxta.chat.entities;


import jxta.chat.util.Constants;
import jxta.chat.util.Constants.MessageParamsKeys;
import net.jxta.endpoint.Message;
import net.jxta.endpoint.MessageElement;
import net.jxta.endpoint.StringMessageElement;

// TODO Remove the class

/**
 * A class that creates Login messages
 *
 */
public class RegularMessage extends AbstractMessage{

	public RegularMessage(){
		
	}
	
	public RegularMessage(Message msg){
		super(msg);
	}
	
	/**
	 * Create a new Message containing the given pipe advertisement
	 * 
	 * @return a message that contains the pipe advertisement sent in the constructor
	 */
	@Override
	public Message createMessage(MessageParams params){
		
		Message retVal = super.createMessage(params);
		
		MessageElement me = new StringMessageElement(Constants.MESSAGE_NAME_SPACE, params.getParameter(MessageParamsKeys.MESSAGE).toString(), null);
		
		retVal.addMessageElement(me);
		
		return retVal;
	}
	
	public String getMessageType(){
		return Constants.MessageTypes.REGULAR.getName();
	}
	
	public String getMessageText(){
		MessageElement me = this.msg.getMessageElement(null, Constants.MESSAGE_NAME_SPACE);
		
		return me != null ? me.toString() : null;
	}
}
